#!/bin/bash

##################
. /etc/profile
. ~/.bash_profile
##################

ipaddr=`/sbin/ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' |cut -d: -f2 | awk '{ print $1}'`
appname="ecommerce_${ipaddr}"
applog=/u01/apache-tomcat-7.0.26/logs

if [ $(hostname) == "publicsyncserver" ];then

        ls -l $0 | grep today_log.sh > /dev/null 2>&1

        if  [ $? -eq 0 ] ;then

            echo "Donot run this script $0,thanks"
            exit 1

        fi

fi





if [ ! -d $applog ];then

	echo "$applog folder no  exit"
	exit 1
fi

if [ -f /mnt/backupall/upload/"$appname"_`date +%F`.tgz ];then

        echo  " file "$appname"_`date +%F`.tgz exit already, clear it first"
        exit 3
fi

cd $applog

find ./  -name "ecommerce*" | xargs tar -czvf "$appname"_`date +%F`.tgz 

if [ ! -f "$appname"_`date +%F`.tgz ];then

	echo " tar "$appname"_`date +%F`.tgz faild "
	exit 2
fi

mv "$appname"_`date +%F`.tgz  /mnt/backupall/upload 

if [ ! -f /mnt/backupall/upload/"$appname"_`date +%F`.tgz ];then

	echo  " upload "$appname"_`date +%F`.tgz faild"
	exit 4
fi
